<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <!-- <label class="el-form-item-label">酒店id</label>
        <el-input v-model="query.hotelId" clearable placeholder="酒店id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <label class="el-form-item-label">姓名</label>
        <el-input v-model="query.userName" clearable placeholder="姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">身份证</label>
        <el-input v-model="query.idCard" clearable placeholder="身份证" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">手机号</label>
        <el-input v-model="query.mobile" clearable placeholder="手机号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">入住时间</label>
        <el-input v-model="query.arriveTime" clearable placeholder="入住时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">创建时间</label>
        <el-input v-model="query.createTime" clearable placeholder="创建时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <!-- <crudOperation :permission="permission" /> -->
      <!--表单组件-->
      <el-dialog style="z-index:3000 !important;" append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="50%">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="房型">
            <el-input v-model="form.roomType" style="" />
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="form.userName" style="" />
          </el-form-item>
          <el-form-item label="身份证">
            <el-input v-model="form.idCard" style="" />
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="form.mobile" style="" />
          </el-form-item>
          <el-form-item label="实付金额">
            <el-input v-model="form.price" style="" />
          </el-form-item>
          <el-form-item label="入住时间">
            <el-input v-model="form.arriveTime" style="" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-input v-model="form.createTime" style="" />
          </el-form-item>
          <el-form-item label="修改时间">
            <el-input v-model="form.modifyTime" style="" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="roomType" label="房型" />
        <el-table-column prop="userName" label="姓名" />
        <el-table-column prop="idCard" label="身份证" />
        <el-table-column prop="mobile" label="手机号" />
        <el-table-column prop="price" label="实付金额" />
        <el-table-column prop="arriveTime" label="入住时间" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="modifyTime" label="修改时间" />
        <el-table-column v-if="checkPer(['admin','hotelOrder:edit','hotelOrder:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudHotelOrder from '@/api/hotelOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import moment from 'moment'
import { mapGetters } from 'vuex'
const defaultForm = { id: null, hotelId: null, roomId: null, roomType: null, userId: null, userName: null, idCard: null, mobile: null, price: null, arriveTime: null, createTime: null, modifyTime: null }
export default {
  name: 'HotelOrder',
  components: { pagination, crudOperation, rrOperation, udOperation },
  props: ['hotelId'],
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '酒店订单', url: 'api/hotelOrder', idField: 'id', sort: 'id,desc', crudMethod: { ...crudHotelOrder }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'hotelOrder:add'],
        edit: ['admin', 'hotelOrder:edit'],
        del: ['admin', 'hotelOrder:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'hotelId', display_name: '酒店id' },
        { key: 'userName', display_name: '姓名' },
        { key: 'idCard', display_name: '身份证' },
        { key: 'mobile', display_name: '手机号' },
        { key: 'arriveTime', display_name: '入住时间' },
        { key: 'createTime', display_name: '创建时间' }
      ]
    }
  },
  computed: {
    ...mapGetters(['user'])

  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      this.query.hotelId = this.hotelId

      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      if (this.crud.status.add) {
        this.$set(this.form, 'userId', this.user.id)
        this.$set(this.form, 'userName', this.user.nickName)
      }
    },
    [CRUD.HOOK.beforeSubmit](form) {
      if (this.crud.status.add) {
        form.form.hotelId = this.hotelId
        const curTime = moment().format('YYYY-MM-DD HH:mm:ss')
        form.form.createTime = curTime
      }
      // if (this.crud.status.edit) {
      //   const curTime = moment().format('YYYY-MM-DD HH:mm:ss')
      //   form.form.modifyTime = curTime
      // }
    }
  }
}
</script>
<style  lang="scss" scoped>
	.el-form {
		display: flex;
		flex-wrap: wrap;
		.el-form-item {
			width: 49%;
			.el-date-editor {
				width: 100%;
			}
			.el-select {
				width: 100%;
			}
			::v-deep .el-input-number {
				width: 100%;
				.el-input {
					.el-input__inner {
						text-align: left !important;
					}
				}
			}
		}
	}
